home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 014 / dex / dex.ms < prev    next >
Text File  |  1995-03-17  |  15KB  |  720 lines

  1. .ND June 28, 1983
  2. .nr LL 6.5i
  3. .nr PO 0.75i
  4. .RP
  5.  
  6. .TL
  7. DEX - Documentation Extraction Utility
  8.  
  9. .AU
  10. Fred Fish
  11.  
  12. .AI
  13. 345 Scottsdale Road
  14. Pleasant Hill, Ca  94523
  15.  
  16. .AB
  17.  
  18. .PP
  19. Dex
  20. is a utility for extracting documentation from program
  21. source files and compiling it into a form suitable for input
  22. to a text formatting program such as the UNIX "nroff" utility.
  23.  
  24. .PP
  25. The primary benefits of a utility like
  26. dex
  27. are:
  28. (1) internal source code documentation is far more
  29. likely to remain current than external documentation, 
  30. (2) the production of updated documentation can be done
  31. largely under computer control.
  32.  
  33. .PP
  34. Dex
  35. was developed by the author to aid in maintaining
  36. documentation for his portable math library (pml).
  37. Thus it is particularly useful in similar applications where
  38. a programming project's source code is split into many small
  39. files.
  40. .AE
  41.  
  42. .bp
  43. .NH 1
  44. INTRODUCTION
  45.  
  46. .PP
  47. Dex
  48. is a utility for extracting documentation from program
  49. source files and compiling it into a form suitable for
  50. input to a text formatting program.  Currently, the only
  51. text formatting program supported is the UNIX^
  52. .FS
  53. ^UNIX is a trademark of Bell Laboratories.
  54. .FE
  55. "nroff" utility.
  56. However, it would be a relatively simple process to extend
  57. the current implementation to support other text processors.
  58.  
  59. .PP
  60. Dex
  61. was originally developed to aid the author in 
  62. maintaining his portable math library (pml) documentation.
  63. However, dex
  64. is useful for virtually any application where a medium to
  65. large program is under development, particularly if the work
  66. is being done simultaneously by several programmers.
  67.  
  68. .PP
  69. Much of the
  70. dex
  71. implementation is done using 
  72. .ul
  73. lex
  74. and
  75. .ul
  76. yacc.
  77. This has greatly reduced the amount of programming effort
  78. required and made constant evolution relatively painless.
  79. It does however effectively restrict usage of
  80. dex
  81. to UNIX
  82. systems since few non-UNIX systems support these development
  83. aids.
  84.  
  85. .bp
  86. .NH 1
  87. SOURCE CODE EXAMPLE
  88.  
  89. .NH 2
  90. C Source Code Sample
  91.  
  92. .PP
  93. The source code format for
  94. dex
  95. usage is quite similar to the
  96. documentation format found in the Unix Programmer's Manual.
  97. This leads to highly readable internal documentation in a familiar
  98. format.
  99. For example, the documentation shown in figure 1 might
  100. precede the source code for a "tolower" library function.
  101. .KF
  102. .sp 3
  103. .nf
  104.    /*
  105.     *  FUNCTION
  106.     *
  107.     *       tolower    convert character to lower case
  108.     *
  109.     *  SYNOPSIS
  110.     *
  111.     *       char tolower(ch)
  112.     *       char ch;
  113.     *
  114.     *  DESCRIPTION
  115.     *
  116.     *       Tolower converts a character from upper case
  117.     *       to lower case. Characters which are already
  118.     *       lower case or are not alphabetic are returned
  119.     *       unmodified.
  120.     *
  121.     *              a   =>   a
  122.     *              A   =>   a
  123.     *              &   =>   &
  124.     *              7   =>   7
  125.     *                  .
  126.     *                 etc
  127.     *
  128.     */
  129. .fi
  130. .sp 2
  131. .ce 1
  132. Figure 1
  133. .ce 1
  134. .ul
  135. Source Code Example
  136. .sp 2
  137. .KE
  138.  
  139. .NH 2
  140. Dex Sample Output
  141.  
  142. .PP
  143. Dex would process the text shown in figure 1, a documentation
  144. .ul
  145. region,
  146. to produce the text formatter source in figure 2.
  147. However, before you try it, at least read the section on dynamic
  148. reconfiguration, since dex will do
  149. .ul
  150. nothing
  151. without the appropriate reconfiguration file.
  152.  
  153. .KF
  154. .nf
  155. .sp 2
  156.     .in 0
  157.     .fi
  158.     .bp
  159.     .sp 3
  160.     .ce
  161.     ***********
  162.     .ce
  163.     * tolower *
  164.     .ce
  165.     ***********
  166.     .sp 3
  167.     .ul 1
  168.     SYNOPSIS
  169.     .sp 1
  170.     .in 8
  171.     .nf
  172.     char tolower(ch)
  173.     char ch;
  174.     .sp 1
  175.     .in 0
  176.     .ul 1
  177.     DESCRIPTION
  178.     .sp 1
  179.     .in 8
  180.     .fi
  181.     Tolower converts a character from upper case
  182.     to lower case. Characters which are already
  183.     lower case or are not alphabetic are returned
  184.     unmodified.
  185.     .sp 1
  186.     .nf
  187.     .in 16
  188.     a   =>   a
  189.     A   =>   a
  190.     &   =>   &
  191.     7   =>   7
  192.         .
  193.        etc
  194.     .sp 1
  195. .fi
  196. .sp 2
  197. .ce 1
  198. Figure 2
  199. .ce 1
  200. .ul
  201. Dex Sample Output
  202. .sp 2
  203. .KE
  204.  
  205. .NH 2
  206. Nroff Sample Output
  207.  
  208. .PP
  209. Dex currently knows nothing about macro packages, so its output
  210. can be intermixed with other nroff source intended for any of the
  211. macro packages  (with restrictions noted in macro package's documentation
  212. concerning command conflicts).
  213. Figure 3 shows the output of nroff for the input of figure 2.
  214.  
  215. .KF
  216. .sp 2
  217. .nf
  218.                            ***********
  219.                            * tolower *
  220.                            ***********
  221.  
  222.  
  223.  
  224. .ul
  225. SYNOPSIS
  226.  
  227.         char tolower(ch)
  228.         char ch;
  229.  
  230. .ul
  231. DESCRIPTION
  232.  
  233.         Tolower converts a character from  upper  case  to  lower
  234.         case.  Characters which are already lower case or are not
  235.         alphabetic are returned unmodified.
  236.  
  237.                 a   =>   a
  238.                 A   =>   a
  239.                 &   =>   &
  240.                 7   =>   7
  241.                     .
  242.                    etc
  243. .fi
  244. .sp 2
  245. .ce 1
  246. Figure 3
  247. .ce 1
  248. .ul
  249. Nroff Sample Output
  250. .sp 2
  251. .in +4
  252. .KE
  253.  
  254. .NH 2
  255. Dynamic Reconfiguration
  256.  
  257. .PP
  258. Dex has
  259. .ul
  260. no
  261. built in knowledge about how to handle each documentation
  262. .ul
  263. topic
  264. (such as "DESCRIPTION")
  265. with respect to formatter modes such
  266. as fill, underline, indent, etc.
  267. This knowledge is obtained via a mechanism referred to as
  268. .ul
  269. dynamic reconfiguration,
  270. whereby a special file is read from the directory containing
  271. the processed source files.
  272. Dex can also be instructed to read a reconfiguration file
  273. of the user's choosing.
  274.  
  275. .PP
  276. Dex does not complain about the absence of the reconfiguration
  277. file and if it is unreadable will essentially do nothing while
  278. processing the specified source files.
  279. In the example of figure 1,
  280. dex
  281. would typically be reconfigured to default to fill
  282. mode for the text of the "DESCRIPTION"
  283. .ul
  284. topic
  285. and to default to nofill mode for the text "SYNOPSIS"
  286. .ul
  287. topic.
  288.  
  289. .bp
  290. .NH 1
  291. DEFINITIONS
  292.  
  293. .PP
  294. To provide a consistent terminology for describing dex usage
  295. some basic "buzz words" need to be defined.
  296.  
  297. .NH 2
  298. Documentation Topic
  299.  
  300. .PP
  301. The basic building block of internal documentation is the documentation
  302. .ul
  303. topic.
  304. A documentation
  305. .ul
  306. topic
  307. is a contiguous section of documentation which begins with recognition
  308. of a topic
  309. .ul 1
  310. identifier
  311. and continues until recognition of
  312. another topic
  313. .ul
  314. identifier,
  315. or program source code (junk).
  316.  
  317. .PP
  318. In the previous example, the topic
  319. .ul
  320. identifiers
  321. are "FUNCTION", "SYNOPSIS", "DESCRIPTION", and "BUGS".
  322. The
  323. .ul
  324. topics
  325. are the topic
  326. .ul
  327. identifiers
  328. along with the corresponding topic
  329. .ul
  330. body
  331. (text).
  332. Thus the "BUGS"
  333. .ul
  334. topic
  335. consists of the the lines shown in figure 4.
  336.  
  337. .KF
  338. .sp 3
  339. .nf
  340. .in +4
  341.  *  BUGS
  342.  *
  343.  *      As implemented only works on systems for which
  344.  *      native character set is ASCII.
  345.  *
  346. .in -4
  347. .fi
  348. .sp 2
  349. .ce
  350. Figure 4
  351. .ul
  352. .ce
  353. Documentation Topic Example
  354. .sp 2
  355. .KE
  356.  
  357. .NH 2
  358. Documentation Region
  359.  
  360. .PP
  361. A documentation
  362. .ul 1
  363. region
  364. is a (possibly non-contiguous) section of documentation
  365. comprised of one or more documentation
  366. .ul
  367. topics.
  368. It begins with recognition of a topic
  369. identifier which has previously been configured to start
  370. a region and continues until another region start identifier
  371. is encountered.
  372.  
  373. .PP
  374. In the example of figure 1, only the topic identifier "FUNCTION"
  375. will generally be flagged as starting a new documentation
  376. region.
  377. Thus the entire C comment is a documentation
  378. region
  379. although it contains no embedded C code between topics.
  380.  
  381. .bp
  382. .NH 1
  383. SOURCE LINE DETAILS
  384.  
  385. .PP
  386. Dex is set up to recognize comment lines for various source file
  387. types.  It recognizes the "*" character as starting a C comment
  388. line, the "#" character as starting "make" and dex reconfiguration
  389. file comment lines, and a ";" character or "|" character
  390. as starting assembler
  391. comment lines.  These characters can be preceeded by any number
  392. of blanks and tabs and must be followed by at least one blank
  393. or tab.
  394.  
  395. .PP
  396. Files processed by dex are divided strings which match one of the following
  397. forms:
  398. .sp 2
  399. .nr LL -0.5i
  400. .in +2
  401. .IP (1)
  402. <blanks/tabs><comment_string><blanks><text><newline>
  403. .bk
  404. Usually contains the topic identifier in the "text" field.
  405. The <blanks> field consists of 2 or more blanks.
  406. .IP (2)
  407. <blanks/tabs><comment_string><tab><text><newline>
  408. .bk
  409. The text is emitted in fill or nofill mode depending
  410. upon the state of the EMITFILL flag (see reconfiguration
  411. section).
  412. .IP (3)
  413. <blanks/tabs><comment_string><tab><tab><text><newline>
  414. .bk
  415. The text is emitted in nofill mode
  416. .ul
  417. regardless
  418. of the state of the EMITFILL flag.
  419. The <text> is anything except newline, including
  420. blanks and tabs.
  421. .IP (4)
  422. .bk
  423. <blanks/tabs><comment_string><newline>
  424. Causes commands for a single blank line to be emitted.
  425. Thus blank comment lines map one for one with blank lines in the
  426. nroff output.
  427. .IP (5)
  428. Any line not beginning with <blanks/tabs> followed
  429. by <comment_string> is 
  430. considered to be "junk" and terminates processing of the
  431. current topic.  Subsequent lines which match (2), (3), or (4) above
  432. will be ignored until the next match of (1).
  433. .in -2
  434. .nr LL +0.5i
  435.  
  436. .PP
  437. Figure 1 is reproduced in figure 5 with each line marked
  438. according to which pattern it matches.  Carefully study
  439. figures 1, 2, 3, and 5 to determine what transformations
  440. are made in going from the source code to the nroff output.
  441. .KF
  442. .sp 2
  443. .nf
  444.     5   /*
  445.     1    *  FUNCTION
  446.     4    *
  447.     2    *       tolower    convert character to lower case
  448.     4    *
  449.     1    *  SYNOPSIS
  450.     4    *
  451.     2    *       char tolower(ch)
  452.     2    *       char ch;
  453.     4    *
  454.     1    *  DESCRIPTION
  455.     4    *
  456.     2    *       Tolower converts a character from upper case
  457.     2    *       to lower case. Characters which are already
  458.     2    *       lower case or are not alphabetic are returned
  459.     2    *       unmodified.
  460.     4    *
  461.     3    *              a   =>   a
  462.     3    *              A   =>   a
  463.     3    *              &   =>   &
  464.     3    *              7   =>   7
  465.     3    *                  .
  466.     3    *                 etc
  467.     4    *
  468.     5    */
  469. .fi
  470. .sp 2
  471. .ce 1
  472. Figure 5
  473. .ce 1
  474. .ul
  475. Source Code Example Revisited
  476. .sp 2
  477. .KE
  478. .PP
  479. Note that there can be any number of leading tabs and
  480. blanks (or none).  Also, lines which have exactly one
  481. tab after the string recognized as starting a comment
  482. can be emitted in either filled or unfilled mode while
  483. lines having two tabs are emitted in unfilled mode
  484. only.  This allows reasonable handling and appearance
  485. of fillable text interspersed with lists or other
  486. non-fillable text.
  487.  
  488. .PP
  489. It should also be pointed out that the file being processed
  490. does
  491. .ul
  492. not
  493. have to be an ASCII text file.  All input bytes are masked
  494. with octal 177 so object files and other non-ASCII files
  495. do not cause problems.  This allows one to scan all
  496. files in a directory, extracting documentation, without
  497. worrying about what kind of files they are.
  498.  
  499.  
  500. .bp
  501. .NH 1
  502. RECONFIGURATION
  503.  
  504. .PP
  505. Dex is designed so that it can be reconfigured
  506. dynamically by placing reconfiguration
  507. instructions in a file in the same directory as the files to
  508. be processed.  
  509. If a file name other than the default 
  510. reconfiguration file is desired, this too can be handled by issuing
  511. the appropriate command line switch when
  512. dex
  513. is invoked.
  514.  
  515. .PP
  516. Each time
  517. dex
  518. processes the first file in any directory it
  519. automagically looks for a file called ".dexrc", the
  520. default dex reconfiguration file.
  521. It will
  522. .ul
  523. not
  524. complain if the file is not found or is unreadable.
  525. Some of the things which can be reconfigured are:
  526. .sp 1
  527. .nr LL -0.5i
  528. .in +4
  529. .IP o
  530. .ul
  531. Topic identifier words:
  532. Specific strings can be added to or removed from the internal
  533. tables.
  534. .IP o
  535. .ul
  536. Fill mode:
  537. The default handling for fill/unfill mode can be enabled or disabled
  538. for specific documentation topics.
  539. .IP o
  540. .ul
  541. Output files:
  542. The output for specific documentation regions can be
  543. redirected to files other than the default standard output.
  544. .IP o
  545. .ul
  546. Processing inhibition:
  547. Processing of specified documentation regions or topics
  548. can be disabled or enabled dynamically.
  549. .nr LL +0.5i
  550. .in -4
  551. .sp 1
  552.  
  553. .NH 2
  554. Reconfiguration File Format
  555.  
  556. .PP
  557. Each line of a reconfiguration file is either a comment or a
  558. reconfiguration directive.  Comments are any lines
  559. beginning with the "#" character (with or without leading
  560. whitespace), a blank, or a form feed character.
  561. The directives currently supported are:
  562. .sp 1
  563. .nr LL -0.5i
  564. .in +8
  565. .ul
  566. .IP \.flags 10
  567. Set or reset flags for a given topic identifier.
  568. .ul
  569. .IP \.output 10
  570. Redirect output to a file for a given topic identifier.
  571. .nr LL +0.5i
  572. .in -8
  573. .sp 1
  574.  
  575. .PP
  576. More than one directive line may be associated with any given
  577. identifier.   Thus, for example, if one line is insufficient to set or
  578. reset all desired flags for the "FILE" identifier, then another
  579. directive can be issued for the remaining flags.
  580.  
  581. .PP
  582. Entries are free format within a given line; whitespace separating
  583. directive fields is simply ignored.  The formats of the current
  584. directives are:
  585. .sp 2
  586. .nf
  587.         .flags  <identifier>  [-]<flag1> [-]<flag2> ...
  588.  
  589.         .output <identifier>  <filename>
  590. .fi
  591. .sp 2
  592.  
  593. .NH 2
  594. Identifier Flags
  595.  
  596. .PP
  597. Flags associated with specified topic identifiers can be set or
  598. reset by the ".flags" reconfiguration directive.  When dex starts
  599. up all flags are initially reset.
  600. They are set by simply naming them in the directive line (a leading
  601. "+" character is optional).
  602. They are reset by naming them with a leading "-" character.  Flags
  603. not named in the reconfiguration file remain unchanged.
  604. The current flags are:
  605. .sp 2
  606. .nr LL -0.5i
  607. .in +8
  608. .IP PROCESS 12
  609. If set then topic is processed, otherwise it is ignored.
  610. .IP EMITTEXT 12
  611. If set then topic text is emitted, otherwise there is not
  612. output while topic is processed.
  613. .IP EMITBOX 12
  614. If set then first word of topic text is emitted enclosed
  615. in a box.  (Doesn't mesh well with EMITTEXT)
  616. .IP EMITFILL 12
  617. If set then text separated from comment string ("*", "#", or
  618. ";") with
  619. a single tab is emitted in fill mode.
  620. .IP EMITUL 12
  621. If set then topic identifier is underlined when emitted.
  622. .IP EMITBP 12
  623. If set then commands to start new page are emitted prior
  624. to topic output (generally used with REGION).
  625. .IP REGION 12
  626. If set then topic identifier is considered to start a new
  627. documentation region.  If PROCESS is simultaneously reset
  628. then
  629. .ul
  630. all
  631. topics until the next region are suppressed.
  632. .nr LL +0.5i
  633. .in -8
  634. .sp 2
  635.  
  636. .NH 2
  637. Reconfiguration File Example
  638.  
  639. .PP
  640. Figure 6 is a reconfiguration file which specifies that the identifier
  641. "FUNCTION" starts a documentation region, the region is to
  642. be processed, the function name is to be printed in a box and
  643. each function starts on a new page.   Also, the identifier "DESCRIPTION"
  644. is for a normal (non-region) topic, the topic is processed, its
  645. text is emitted, the emitted text is fill mode by default, and
  646. the identifier is to be underlined when printed.
  647. .KF
  648. .nf
  649. .sp 3
  650.       .flags "FUNCTION"     REGION PROCESS EMITBOX EMITBP
  651.       .flags "DESCRIPTION" -REGION PROCESS EMITTEXT
  652.       .flags "DESCRIPTION"  EMITUL EMITFILL
  653. .sp 2
  654. .ce
  655. Figure 6
  656. .ul
  657. .ce
  658. Reconfiguration File Example
  659. .fi
  660. .sp 2
  661. .KE
  662.  
  663. .bp
  664. .NH 1
  665. MISCELLANEOUS
  666.  
  667. .NH 2
  668. Usage
  669.  
  670. .PP
  671. Dex is invoked with a command line of the form:
  672. .sp 2
  673. .nf
  674.     dex [-dhtv] [-r rcfile] file1 file2 file3 ...
  675.  
  676.         d =>  enable debug mode
  677.         h =>  print internal help message
  678.         t =>  enable trace mode
  679.         v =>  enable verbose mode
  680.  
  681.         r =>  use reconfiguration file <rcfile>
  682. .fi
  683. .sp 1
  684.  
  685. .NH 2
  686. Style Notes
  687.  
  688. .PP
  689. The following order is suggested for topics within a documentation region.
  690. It roughly follows the order which appears in the Unix Programmer's Manual.
  691.  
  692. .sp 1
  693. .in +4
  694. .IP o
  695. FUNCTION or FILE or TOOL or NAME
  696. .IP o
  697. KEY WORDS
  698. .IP o
  699. SYNOPSIS
  700. .IP o
  701. DESCRIPTION
  702. .IP o
  703. RETURNS
  704. .IP o
  705. EXAMPLE
  706. .IP o
  707. FILES
  708. .IP o
  709. SEE ALSO
  710. .IP o
  711. DIAGNOSTICS
  712. .IP o
  713. WARNINGS or CAVEATS or RESTRICTIONS or BUGS
  714. .IP o
  715. AUTHOR
  716. .IP o
  717. PSEUDO CODE
  718. .in -4
  719. .sp 2
  720.